<?php

class Point_orderController extends BaseController
{
    /*
     * 确认收货接口
     */
    public function getExpressAction() {
        $orderId = Request::getParams('orderId');
        $orderInfo = self::model('point_order')->getOne('id=?', [$orderId]);
        if(!$orderInfo||$orderInfo['uid']!=$this->user_info['uid']) {
            Response::ajax(NORMAL_ERROR, '参数错误,订单查看失败');
        }
        if($orderInfo['order_status']== point_orderModel::ORDER_STATUS_PAIED) {
            Response::ajax(NORMAL_ERROR, '订单未发货,无法确认');
        }
        if($orderInfo['order_status']== point_orderModel::ORDER_STATUS_USER_SIGN) {
            Response::ajax(NORMAL_ERROR, '订单已确认收货');
        }
        if($orderInfo['order_status']== point_orderModel::ORDER_STATUS_FINISH) {
            Response::ajax(NORMAL_ERROR, '订单已完成');
        }
        if(self::model('point_order')->userSign($orderInfo)){
            Response::ajax(200, '订单确认成功');
        }
        Response::ajax(SYSTEM_ERROR, '订单确认失败');
    }
    
    /*
     * 确认完成接口
     */
    public function confirmAction() {
        $orderId = Request::getParams('orderId');
        $orderInfo = self::model('point_order')->getOne('id=?', [$orderId]);
        if(!$orderInfo||$orderInfo['uid']!=$this->user_info['uid']) {
            Response::ajax(NORMAL_ERROR, '参数错误,订单查看失败');
        }
        if($orderInfo['order_status']== point_orderModel::ORDER_STATUS_PAIED) {
            Response::ajax(NORMAL_ERROR, '订单未发货,无法确认');
        }
        if($orderInfo['order_status']== point_orderModel::ORDER_STATUS_FINISH) {
            Response::ajax(NORMAL_ERROR, '订单已完成');
        }
        if(self::model('point_order')->finish($orderInfo)){
            Response::ajax(200, '订单完成');
        }
        Response::ajax(SYSTEM_ERROR, '订单确认失败');
    }
}